home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / scout_fonts.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-02-13  |  8.9 KB  |  281 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28.  
  29.  
  30. #include "system_headers.h"
  31.  
  32. APTR BT_FontUpdate,BT_FontPrint,BT_FontClose,BT_FontRemove,BT_FontExit;
  33. APTR fonttext,fontlist,LB_FontExample;
  34.  
  35. APTR fontcount;
  36. int  fontcnt;
  37.  
  38. static APTR FontPool = NULL;
  39.  
  40. __asm __saveds LONG fontlist_dspfunc(register __a2 char **array, register __a1 struct FontEntry *fontentry, register __a0 struct Hook *hook)
  41. {
  42.     if (fontentry) {
  43.         *array++ = fontentry->font_address;
  44.         *array++ = fontentry->font_ysize;
  45.         *array++ = fontentry->font_xsize;
  46.         *array++ = fontentry->font_style;
  47.         *array++ = fontentry->font_flags;
  48.         *array++ = fontentry->font_count;
  49.         *array++ = fontentry->font_lochar;
  50.         *array++ = fontentry->font_hichar;
  51.         *array++ = fontentry->font_place;
  52.         *array++ = fontentry->font_name;
  53.         *array   = NULL;
  54.     } else {
  55.         *array++ = ESC "bAddress";
  56.         *array++ = ESC "bYSize";
  57.         *array++ = ESC "bXSize";
  58.         *array++ = ESC "bStyle";
  59.         *array++ = ESC "bFlags";
  60.         *array++ = ESC "bCount";
  61.         *array++ = ESC "bLoChar";
  62.         *array++ = ESC "bHiChar";
  63.         *array++ = ESC "bType";
  64.         *array++ = ESC "bName";
  65.         *array   = NULL;
  66.     }
  67.     return(0);
  68. }
  69.  
  70. struct Hook fontlist_dsphook = {
  71.  {NULL, NULL},
  72.  (ULONG (* )())fontlist_dspfunc,
  73.  NULL, NULL
  74. };
  75.  
  76. __asm __saveds LONG fontlist_cmpfunc(register __a1 struct FontEntry *fontentry1, register __a2 struct FontEntry *fontentry2)
  77. {
  78.     LONG cmp;
  79.  
  80.     cmp = strcmpi(fontentry1->font_name, fontentry2->font_name);
  81.     if (cmp == 0) cmp = strcmpi(fontentry1->font_ysize, fontentry2->font_ysize);
  82.     if (cmp == 0) cmp = strcmpi(fontentry1->font_xsize, fontentry2->font_xsize);
  83.  
  84.     return cmp;
  85. }
  86.  
  87. struct Hook fontlist_cmphook = {
  88.  {NULL, NULL},
  89.  (ULONG (* )())fontlist_cmpfunc,
  90.  NULL, NULL
  91. };
  92.  
  93. void FreeFonts (void)
  94. {
  95.     MyFreePoolStructs(&FontPool, fonttext, NULL, fontlist);
  96. }
  97.  
  98. void FlushFonts (void) {
  99.     struct TextFont *font, *next;
  100.  
  101.     font = FIRSTFONT;
  102.  
  103.     Forbid();
  104.     while (next = (struct TextFont *)font->tf_Message.mn_Node.ln_Succ) {
  105.         if ((! font->tf_Accessors) && (font->tf_Flags & FPF_DISKFONT)) {
  106.             RemFont (font);
  107.             Remove ((struct Node *) font);
  108.         }
  109.         font = next;
  110.     }
  111.     Permit();
  112. }
  113.  
  114. int GetFonts (struct FontEntry **first) {
  115.    struct   FontEntry   *fontentry,*previous = NULL;
  116.    struct   TextFont    *font;
  117.  
  118.    int fontcnt = 0;
  119.    *first = 0;
  120.  
  121.    if (!FontPool) FontPool = tbCreatePool(MEMF_CLEAR, 4096, 4096);
  122.  
  123.    if (clientstate) {
  124.       if (SendDaemon ("GetFontList")) {
  125.          while ((fontentry = tbAllocPooled(FontPool, sizeof(struct FontEntry))) \
  126.            && (ReceiveDecodedEntry ((UBYTE *) fontentry, sizeof (struct FontEntry)))) {
  127.             IsHex (fontentry->font_address, (long *) &fontentry->font_adr);
  128.  
  129.             if (! *first)
  130.                *first = fontentry;
  131.             if (previous)
  132.                previous->font_next = fontentry;
  133.  
  134.             fontcnt++;
  135.             previous = fontentry;
  136.          }
  137.       }
  138.    } else {
  139.       font = FIRSTFONT;
  140.  
  141.       while ((font->tf_Message.mn_Node.ln_Succ != 0) && (fontentry = tbAllocPooled(FontPool, sizeof(struct FontEntry)))) {
  142.          if (! *first)
  143.             *first = fontentry;
  144.          if (previous)
  145.             previous->font_next = fontentry;
  146.  
  147.                 fontentry->font_adr = font;
  148.  
  149.                 _sprintf (fontentry->font_address, "$%08lx", font);
  150.                 _sprintf (fontentry->font_xsize, "%3ld ", font->tf_XSize);
  151.                 _sprintf (fontentry->font_ysize, "%3ld ", font->tf_YSize);
  152.                 _sprintf (fontentry->font_style, " $%02lx", font->tf_Style);
  153.                 _sprintf (fontentry->font_flags, " $%02lx", font->tf_Flags);
  154.                 _sprintf (fontentry->font_lochar, "%4ld ", font->tf_LoChar);
  155.                 _sprintf (fontentry->font_hichar, "%4ld ", font->tf_HiChar);
  156.                 _sprintf (fontentry->font_count, "%3ld ", font->tf_Accessors);
  157.                 if (font->tf_Flags & FPF_ROMFONT) {
  158.                         strcpy (fontentry->font_place, "ROMFONT ");
  159.                 } else {
  160.                         strcpy (fontentry->font_place, "DISKFONT");
  161.                 }
  162.                 strcpy (fontentry->font_name, font->tf_Message.mn_Node.ln_Name);
  163.          fontcnt++;
  164.    
  165.          previous = fontentry;
  166.          font = (struct TextFont *) font->tf_Message.mn_Node.ln_Succ;
  167.       }
  168.    }
  169.    return (fontcnt);
  170. }
  171.  
  172. void PrintFonts (char *filename) {
  173.    int i=1;
  174.    BPTR handle;
  175.    struct FontEntry *entryp = NULL;
  176.  
  177.    handle = HandlePrintStart (filename);
  178.    if ((handle) && (PrintOneLine (handle, "\n  Address  XSize YSize Style Flags Count LoChar HiChar Type     Name\n\n"))) {
  179.       if (! WI_Fonts) {
  180.          i = GetFonts (&entryp);
  181.       }
  182.       if (i) {
  183.          for (i=0;;i++) {
  184.             if (WI_Fonts)
  185.                DoMethod (fontlist,MUIM_List_GetEntry,i,&entryp);
  186.             if (!entryp) break;
  187.  
  188.             _sprintf (tmpstr2, " %s  %3s %3s %s  %s   %3s  %4s  %4s %-8s %s\n", entryp->font_address, entryp->font_xsize, entryp->font_ysize, entryp->font_style, entryp->font_flags, entryp->font_count, entryp->font_lochar, entryp->font_hichar, entryp->font_place, entryp->font_name);
  189.             if (! (PrintOneLine (handle, tmpstr2)))
  190.                break;
  191.  
  192.             if (! WI_Fonts)
  193.                entryp = entryp->font_next;
  194.          }
  195.       }
  196.    }
  197.    HandlePrintStop();
  198. }
  199.  
  200. void ShowFonts (void) {
  201.    struct   FontEntry   *font;
  202.  
  203.         ApplicationSleep();
  204.         set(fontlist,MUIA_List_Quiet,TRUE);
  205.         set(BT_FontClose, MUIA_Disabled, TRUE);
  206.         set(BT_FontRemove, MUIA_Disabled, TRUE);
  207.  
  208.    fontcnt = GetFonts (&font);
  209.  
  210.    while (font) {
  211.       InsertSortedEntry (fontlist, (APTR *) &font);
  212.       font = font->font_next;
  213.    }
  214.  
  215.    SetCountText (fontcount, fontcnt);
  216.         AwakeApplication();
  217.         set(fontlist,MUIA_List_Quiet,FALSE);
  218. }
  219.  
  220. void SendFontList (void) {
  221.    struct   FontEntry   *font;
  222.  
  223.    fontcnt = GetFonts (&font);
  224.  
  225.    while (font) {
  226.       SendEncodedEntry ((UBYTE *) font, sizeof (struct FontEntry));
  227.       font = font->font_next;
  228.    }
  229.    FreeFonts();
  230. }
  231.  
  232.  
  233. char fonts_title[WINDOWTITLELEN];
  234.  
  235. void FontsWindow (BOOL state) {
  236.    if (state) {
  237.       if (WI_Fonts) {
  238.          ShowFonts();
  239.       } else {
  240.          WI_Fonts = WindowObject,
  241.          MUIA_Window_Title, MyGetWindowTitle (fonts_title, "FONTS"),
  242.          MUIA_HelpNode, FontsText,
  243.          MUIA_Window_ID, MakeListID('F','O','N','T'),
  244.          WindowContents, VGroup,
  245.             Child, fontlist = MySortedListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8 P=\33r,COL=2 DELTA=8 P=\33r,COL=3 DELTA=8,COL=4 DELTA=8,COL=5 DELTA=8 P=\33r,COL=6 DELTA=8 P=\33r,COL=7 DELTA=8 P=\33r,COL=8 DELTA=8,COL=9",&fontlist_dsphook, &fontlist_cmphook),
  246.             Child, MyBelowListview (&fonttext, &fontcount),
  247.             Child, MyVSpace(2),
  248.             Child, LB_FontExample = NewObject(FontDisplayClass->mcc_Class, NULL, TextFrame, MUIA_Background, MUII_BACKGROUND, FDATTR_Font, NULL, TAG_DONE),
  249.             Child, MyVSpace(2),
  250.             Child, HGroup, MUIA_Group_SameSize, TRUE,
  251.                Child, BT_FontUpdate  = KeyButtonA (UpdateText,ID_FONTUPDATE),
  252.                Child, BT_FontPrint   = KeyButtonA (PrintText ,ID_FONTPRINT),
  253.                Child, BT_FontClose   = KeyButtonA (CloseText,ID_FONTCLOSE),
  254.                Child, BT_FontRemove  = KeyButtonA (RemoveText,ID_FONTREMOVE),
  255.                Child, BT_FontExit    = KeyButtonA (ExitText  ,ID_FONTEXIT),
  256.             End,
  257.          End, End;
  258.  
  259.          DoMethod (AP_Scout,OM_ADDMEMBER,WI_Fonts);
  260.          DoMethod (WI_Fonts,MUIM_Window_SetCycleChain,fontlist,BT_FontUpdate,BT_FontPrint,BT_FontClose,BT_FontRemove,BT_FontExit,NULL);
  261.  
  262.          SetCloseRequest (WI_Fonts,ID_FONTEXIT);
  263.          SetListActive (fontlist,ID_FONTLV_ACTIVE);
  264.  
  265.          ShowFonts();
  266.  
  267.          SetWindowOpen (WI_Fonts,fontlist,ID_FONTEXIT);
  268.       }
  269.    } else if ((! state) && (WI_Fonts)) {
  270.       SetWindowClose (WI_Fonts,TRUE);
  271.  
  272.       FreeFonts();
  273.  
  274.       DoMethod (AP_Scout,OM_REMMEMBER,WI_Fonts);
  275.       MUI_DisposeObject (WI_Fonts);
  276.       WI_Fonts = NULL;
  277.       fontlist = NULL;
  278.    }
  279. }
  280.  
  281.